package com.jyw.business.ins.controller;

import com.jyw.business.ast.domain.dto.web.InsUnitAstPageDto;
import com.jyw.business.ast.domain.vo.web.InsUnitAstPageVO;
import com.jyw.business.ast.service.IAstInfoService;
import com.jyw.business.ins.domain.dto.web.InsUnitAddDto;
import com.jyw.business.ins.domain.dto.web.InsUnitEditDto;
import com.jyw.business.ins.domain.dto.web.InsUnitPageDto;
import com.jyw.business.ins.domain.dto.web.InsUnitStateDto;
import com.jyw.business.ins.domain.vo.web.InsUnitInfoVO;
import com.jyw.business.ins.domain.vo.web.InsUnitPageVO;
import com.jyw.business.ins.service.IInsUnitService;
import com.jyw.common.annotation.Log;
import com.jyw.common.core.controller.BaseController;
import com.jyw.common.core.domain.CommonResult;
import com.jyw.common.core.page.TableDataInfo;
import com.jyw.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * 巡检单元Controller
 *
 * @author zhangcheng
 * @date 2023-09-21
 */
@Api(tags = "巡检单元")
@RestController
@RequestMapping("/inspection/unit")
public class InsUnitController extends BaseController {
    @Resource
    private IInsUnitService insUnitService;

    @Resource
    private IAstInfoService astInfoService;

    /**
     * 查询巡检单元列表
     */
    @ApiOperation("查询巡检单元列表")
    @PreAuthorize("@ss.hasPermi('inspection:unit:list')")
    @GetMapping("/list")
    public TableDataInfo<InsUnitPageVO> list(InsUnitPageDto insUnitPageDto) {
        startPage();
        List<InsUnitPageVO> list = insUnitService.pageInsUnitList(insUnitPageDto);
        return getDataTable(list);
    }

    /**
     * 查询巡检单元资产选择列表
     */
    @ApiOperation("查询巡检单元资产选择列表")
    @PreAuthorize("@ss.hasPermi('inspection:unit:unitAstList')")
    @GetMapping("/unitAstList")
    public TableDataInfo<InsUnitAstPageVO> unitAstList(InsUnitAstPageDto insUnitAstPageDto) {
        startPage();
        List<InsUnitAstPageVO> list = astInfoService.pageUnitAstList(insUnitAstPageDto);
        return getDataTable(list);
    }

    /**
     * 查询巡检单元资产
     */
    @ApiOperation("查询巡检单元资产")
    @GetMapping("/findAstById/{id}")
    public CommonResult<List<InsUnitAstPageVO>> findAstById(@PathVariable("id") Long id) {
        List<InsUnitAstPageVO> list = insUnitService.findAstById(id);
        return CommonResult.success(list);
    }

    /**
     * 获取巡检单元详细信息
     */
    @ApiOperation("获取巡检单元详细信息")
    @PreAuthorize("@ss.hasPermi('inspection:unit:query')")
    @GetMapping(value = "/{id}")
    public CommonResult<InsUnitInfoVO> getInfo(@PathVariable("id") Long id) {
        return CommonResult.success(insUnitService.findInfoById(id));
    }

    /**
     * 新增巡检单元
     */
    @ApiOperation("新增巡检单元")
    @PreAuthorize("@ss.hasPermi('inspection:unit:add')")
    @Log(title = "巡检单元", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public CommonResult add(@RequestBody @Valid InsUnitAddDto insUnitAddDto) {
        return CommonResult.success(insUnitService.insertInsUnit(insUnitAddDto));
    }

    /**
     * 修改巡检单元
     */
    @ApiOperation("修改巡检单元")
    @PreAuthorize("@ss.hasPermi('inspection:unit:edit')")
    @Log(title = "巡检单元", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public CommonResult edit(@RequestBody @Valid InsUnitEditDto insUnitEditDto) {
        return CommonResult.success(insUnitService.updateInsUnit(insUnitEditDto));
    }

    /**
     * 修改巡检单元状态
     */
    @ApiOperation("修改巡检单元状态")
    @PreAuthorize("@ss.hasPermi('inspection:unit:editState')")
    @Log(title = "巡检单元", businessType = BusinessType.UPDATE)
    @PutMapping("/editState")
    public CommonResult editState(@RequestBody @Valid InsUnitStateDto insUnitStateDto) {
        return CommonResult.success(insUnitService.updateState(insUnitStateDto));
    }

    /**
     * 删除巡检单元
     */
    @ApiOperation("删除巡检单元")
    @PreAuthorize("@ss.hasPermi('inspection:unit:remove')")
    @Log(title = "巡检单元", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public CommonResult remove(@PathVariable Long[] ids) {
        return CommonResult.success(insUnitService.deleteInsUnitByIds(ids));
    }
}
